<template>
  <div class="container">
    <div class="opt-area-02">
      <div class="input-frame" style="width: 100%;text-alone:left;margin-bottom:10px;">
        &nbsp;&nbsp;&nbsp;&nbsp;总人数: <span>{{params.totalRecord}}</span>
      </div>
      <div class="left-con">
        <div class="input-frame" style="width: 164px">
          <Input type="text" @on-click="selectlist(1)" placeholder="请输入姓名" style="width: 164px" v-model="params.name"
                 icon="ios-search"/>
        </div>
        <div class="input-frame" style="width: 164px">
          <Input type="text" @on-click="selectlist(1)" placeholder="请输入身份证号" style="width: 164px" v-model="params.cardno"
                 icon="ios-search"/>
        </div>
        <div class="input-frame" style="width: 164px">
          <Input type="text" @on-click="selectlist(1)" placeholder="请输入联系方式" style="width: 164px" v-model="params.mobile"
                 icon="ios-search"/>
        </div>
        <Button type="info" size="small" @click="selectlist(1)" style="margin-top: 5px">搜索</Button>
      </div>
    </div>
    <Table :loading="countData.loading" border :columns="columns2" :data="DataList" size="small" ref="table">
      <template slot="action" slot-scope="{ row }">
        <Row style="margin-bottom: 5px; margin-top: 2px">
          <Button class="table-action-btn" type="success" size="small" @click="fillUserInfo(row)">编辑</Button>
        </Row>
      </template>
    </Table>
    <Row v-if="loadData == true">
      <Col class="demo-spin-col" span="8" offset="8">
        <Spin fix>
          <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
          <div>Loading</div>
        </Spin>
      </Col>
    </Row>
    <Row type="flex" justify="end" class="page_style">
      <Page :current="params.pageNo" :total="params.totalRecord" show-sizer :page-size="params.pageSize"
            show-total @on-change="pageAction" @on-page-size-change="pageSizeChange"/>
    </Row>
    <person-info-modal :user-info="userInfo" :control-data="controlData" :severUserInfo="severUserInfo" ref="photo"></person-info-modal>
  </div>
</template>

<script>
import { findUserList, userinfo } from '@/api/eventlist'
import PersonInfoModal from '@/view/xian-page/mainv3/components/personInfoModal'
export default {
  name: 'someuserlist',
  components: {
    PersonInfoModal
  },
  data () {
    return {

      loadData: true,
      loading: false,
      modalStr: '',
      id: '',
      row: {},
      countData: { loading: false },
      params: { name: '', pageNo: 1, pageSize: 10, totalRecord: 0, cardno: '', mobile: '' },
      columns2: [
        { title: '姓名', key: 'name', width: 100, align: 'center' },
        { title: '联系方式', key: 'TMmobile', width: 120, align: 'center' },
        { title: '身份证号', key: 'TMcardno', width: 160, align: 'center' },
        { title: '性别', key: 'sex', width: 80, align: 'center' },
        { title: '具体地址', key: 'present_address', minWidth: 250, align: 'center' },
        { title: '操作', align: 'center', width: 160, slot: 'action', fixed: 'right' }
      ],
      DataList: [],
      userOverall: {},
      controlData: {
        show1: false,
        uploadHeader: false,
        readType: 1, // 读取当前人员信息的方式 0未读取 1输入卡号 2读身份证 3人脸对比
        cardnoInput: '',
        showDetail: false,
        photo: '',
        personTags: []
      },
      userInfo: {},
      severUserInfo: {}
    }
  },
  methods: {
    pageAction (page) {
      this.params.pageNo = page
      this.getList()
    },
    selectlist () {
      this.params.pageNo = 1
      this.getList()
    },
    getList () {
      findUserList(this.params).then(res => {
        if (res.data.errcode === 0) {
          this.DataList = res.data.data.results
          this.loadData = false
          this.params.totalRecord = res.data.data.totalRecord
        } else {
          this.loadData = true
          this.$Notice.error({
            title: '查询列表信息失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    pageSizeChange (e) {
      this.params.pageSize = e
      this.selectlist(this.params.pageNo)
    },
    // 完善用户信息
    fillUserInfo (item) {
      this.userOverall = item
      if (!this.userOverall.id) return
      this.getUserInfo(item.cardno)
      this.controlData.showDetail = true
    },
    getUserInfo (cardno) {
      this.controlData.cardno = cardno
      this.userOverall.cardno = cardno
      userinfo(cardno).then(res => {
        if (res.data.errcode === 0) {
          this.userInfo = res.data.data
          if (this.userInfo.photo === undefined) {
            this.userInfo.photo = ''
          }
          this.$refs.photo.photoShow(this.userInfo.photo)
          if (this.userInfo.focus_group) {
            this.controlData.personTags = this.userInfo.focus_group.split(',')
          } else {
            this.controlData.personTags = []
          }
          // 不论是否上传头像，查询个人信息时包含头像则不上传
          if (this.userInfo.photo) {
            this.controlData.photo = this.userInfo.photo
            this.controlData.uploadHeader = false
          } else {
            this.controlData.photo = this.controlData.photo || this.nophoto
          }
          if (this.controlData.readType !== 2) {
            this.userOverall.name = this.userInfo.name
            this.userOverall.address = this.userInfo.address
            this.userOverall.sex = this.userInfo.sex
            this.userOverall.folk = this.userInfo.folk
          }
          this.userOverall.readCount++
          this.userOverall.id = this.userInfo.id
          this.userOverall.userInfo = this.userInfo
        } else {
          this.$Notice.error({ title: '查询失败！', desc: res.data.errmsg })
        }
      })
    }
  },
  mounted () {
    this.severUserInfo = this.$store.state.user.severUserInfo
    this.getList()
  }
}
</script>

<style scoped>
  .page_style {
    margin: 20px 5px;
  }

  .input-frame {
    width: 120px;
    margin-right: 10px;
    float: left;
  }

  .house-list > .group {
    background: white;
    padding: 10px;
    margin-top: 10px;
  }

  .house-list > .group > .item {
    border-bottom: 1px solid #f5f5f5;
    padding: 10px 0;
  }

  .house-list > .group > .item .top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
  }

  .house-list > .group > .item .title {
    font-size: 14px;
    color: #333333;
  }

  .house-list > .group > .item .address {
    font-size: 12px;
    color: gray;
    display: flex;
    align-items: center;
  }

  .house-list > .group > .item .detail {
    font-size: 12px;
    color: dodgerblue;
  }

  .opt-area-02 {
    display: flex;
    align-items: center;
    flex-direction: column;
    border: 1px solid #abdcff;
    background-color: #f0faff;
    padding: 8px 16px 8px 16px;
    border-radius: 4px;
    margin-bottom: 10px;
  }

  .opt-area-02 .right-con {
    width: 100%;
    margin-top: 5px;
    display: flex;
  }

  .opt-area-02 .left-con {
    font-size: 14px;
    width: 100%;
  }

  .opt-area-02 .left-con span {
    font-weight: bold;
  }

  .opt-area-02 .right-con input {
    width: 150px;
    margin-right: 10px;
  }

  .opt-area-02 .right-con .input-frame {
    width: 200px;
    margin-right: 10px;
  }

  .table-action-btn {
    margin-right: 3px;
  }

  .container >>> .ivu-btn-small {
    height: 24px;
    padding: 0 5px;
    font-size: 12px;
    border-radius: 3px;
  }

  .btn-action {
    margin-bottom: 10px;
  }

  .mp10 {
    margin-right: 10px;
  }
  .title-style {
    color: red;
  }
  .mb20 {
    margin-bottom: 20px;
  }
  .ivu-table-row {
    height: 57px;
  }
  .demo-spin-icon-load{
    animation: ani-demo-spin 1s linear infinite;
  }
  @keyframes ani-demo-spin {
    from { transform: rotate(0deg);}
    50%  { transform: rotate(180deg);}
    to   { transform: rotate(360deg);}
  }
  .demo-spin-col{
    height: 100px;
    position: relative;
    /*border: 1px solid #eee;*/
  }
</style>
